<template>
    <div>
        <el-container>
            <el-main>
                <div class="report">
                    <p>
                        初访结果 <el-button size="large" type="primary" @click="dialogTableVisible=true" style="background-color: #409EFF;border-color: #409EFF;color:#fff;">添加</el-button>
                    </p>
                </div>
                <div clss="report-info-body">
                    <div>
                        <el-table fixed :data="reportForm" stripe style="width: 100%" max-height="500">
                            <el-table-column prop="tea_name" label="初访师" align="center"></el-table-column>
                            <el-table-column prop="stu_name" label="学生姓名" align="center"></el-table-column>
                            <el-table-column prop="disease_level" label="问题级别" align="center"></el-table-column>
                            <el-table-column prop="disease_type" label="问题种类" align="center"></el-table-column>
                            <el-table-column prop="visitResult" label="初访结果"  align="center"></el-table-column>
                        </el-table>
                    </div>
                </div>
                <div>
                    <el-dialog title="初访结果" v-model="dialogTableVisible" :before-close="handleClose">
                        <el-form :model="formData">
                            <el-form-item label="初访师" prop="tea_name" style="width: 80%;" >
                                <el-select v-model="formData.tea_name" >
                                    <el-option
                                            v-for="item in firstTea"
                                            :label="item.stuName"
                                            :value="item.stuName"
                                            :key="item.stuName"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="学生姓名" prop="stu_name" style="width: 80%;">
                                <el-select v-model="formData.stu_name" >
                                    <el-option
                                            v-for="item in Stus"
                                            :label="item.stuName"
                                            :value="item.stuName"
                                            :key="item.stuName"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="问题级别" prop="disease_level" style="width: 80%;">
                                <el-input name="disease_type" v-model="formData.disease_level" ></el-input>
                            </el-form-item>
                            <el-form-item label="问题种类" prop="disease_type" style="width: 80%;">
                                <el-input name="disease_type" v-model="formData.disease_type" ></el-input>
                            </el-form-item>
                            <el-form-item label="初访结果" prop="visitResult" style="width: 80%;">
                                <el-select v-model="formData.visitResult" >
                                    <el-option
                                            v-for="item in Level"
                                            :label="item.dataValue"
                                            :value="item.dataKey"
                                            :key="item.dataKey"></el-option>
                                </el-select>
                            </el-form-item>
                        </el-form>
                        <template #footer>
                            <el-button @click="dialogTableVisible = false">取消</el-button>
                            <el-button type="primary" @click="EditSubmit">提交</el-button>
                        </template>
                    </el-dialog>
                </div>
            </el-main>
        </el-container>
    </div>
</template>

<script>
    import request from "../../utils/request";
    import {ElMessage} from "element-plus";

    export default {
        name: "first_visit_result",
        data(){
            return{
                disabled:true,
                dialogTableVisible : false,
                Level:[],
                firstTea:[],
                Stus:[],
                reportForm:[{
                    id:'',
                    visId:'',
                    stuId:'',
                    stu_name:'',
                    visitResult:'',
                    teaId:'',
                    tea_name:'',
                    disease_level:'',
                    disease_type:'',
                    visit_time:'',
                }],
                formData:{
                    id:'',
                    visId:'',
                    stuId:'',
                    visitResult:'',
                    teaId:'',
                    isDelete:'',
                    disease_level:'',
                    disease_type:'',
                    visit_time:'',
                }
            }
        },

        methods :{

            getfirstTea(){
                return request({
                    url: '/api/user/role/firstvisit',
                    method: 'get'
                })
            },

            get_firstTea(){
                this.getfirstTea().then(res=>{
                    if(res.code === 1){
                        console.log(res)
                        this.firstTea = res.data
                    }
                })
            },


            getstu(){
                return request({
                    url:'/api/user',
                    method:'get'
                })
            },

            get_stu(){
                this.getstu().then(res=>{
                    if(res.code===1){
                        console.log(res)
                        this.Stus=res.data
                    }
                })
            },


            submitresult(query){
                return request({
                    url:'/api/visitResult/addvisitRessult',
                    method:'post',
                    data: query,
                })
            },


            async EditSubmit(){
                this.dialogTableVisible =false
                this.firstTea.forEach(x =>{
                    console.log(x)
                    if(this.formData.tea_name===x.stuName){
                        this.formData.teaId = x.id
                    }
                })
                this.Stus.forEach(x =>{
                    console.log(x)
                    if(this.formData.stu_name===x.stuName){
                        this.formData.stuId = x.id
                    }
                })
                this.Level.forEach(x =>{
                    console.log(x)
                    if(this.formData.visitResult===x.dataKey){
                        this.formData.visId = x.id
                    }
                })
                await console.log(this.formData)
                this.submitresult(this.formData).then(res=>{
                    if(res.code === 1 ) {
                        console.log(res)
                        this.getData()
                        ElMessage.success(res.data)
                    }else{
                        ElMessage.error(res.data);
                    }
                })
                console.log('提交')
            },


            getlevel(){
                return request({
                    url:'/api/visitResult/getdiseaseResuldict',
                    method:'get'
                })
            },

            get_Level(){
                this.getlevel().then(res => {
                    if(res.code ===1) {
                        this.Level = res.data;
                        console.log(res.data)
                    }
                })
            },

            // isResult(row) {
            //     if (row.visitResult === 1 ){
            //         return '无需咨询'
            //     }
            //     if (row.visitResult === 2 ){
            //         return '安排咨询'
            //     }
            //     if (row.visitResult === 3 ){
            //         return '转介送诊'
            //     }
            // },

            EditForm : function (index,row) {
                this.dialogTableVisible = true;
                this.formData = Object.assign({},row);
            },

            handleClose(done) {
                this.$confirm('确认关闭？')
                    .then(_ => {
                        done();
                    })
                    .catch(_ => {});
            },


            getClosedReport(){
                return request({
                    url:'/api/visitResult/getall',
                    method:'get'
                })
            },
            //获取数据
            getData(){
                this.getClosedReport().then(res => {
                    if(res.code ===1) {
                        this.reportForm = res.data;
                        console.log(res.data)
                    }
                })
            },
        },
        created() {
            this.getData()
            this.get_Level()
            this.get_stu()
            this.get_firstTea()
        }
    }
</script>

<style scoped>
    .report {
        width: auto;
        height: 56px;
        background-color: #EDEFF2;
        font-size: 22px;
        /* font-family: SimHei; */
        font-weight: 400;
        color: #333333;
        line-height: 48px;
        border-left: 6px solid #409EFF;
        text-align: left;
    }
</style>